package br.edu.ufcg.lsd.wbis.ui.client.beans;

import java.io.Serializable;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo.UserPermission;

/**
 * @author Renato Miceli
 */
public class UserMatcher implements Serializable {

	private static final long serialVersionUID = -5612999347077842393L;

	public static enum StringMatchingType {
		DEFAULT, CONTAINS, STARTS_WITH, ENDS_WITH;
	}

	/**
	 * The matching name.
	 */
	private String name;

	private Boolean nameSensitive;
	
	/**
	 * The matching name checking type.
	 */
	private StringMatchingType nameType;
	
	/**
	 * The matching email.
	 */
	private String email;

	private Boolean emailSensitive;
	
	/**
	 * The matching email checking type.
	 */
	private StringMatchingType emailType;
	
	/**
	 * The matching login.
	 */
	private String login;

	private Boolean loginSensitive;
	
	/**
	 * The matching login checking type.
	 */
	private StringMatchingType loginType;
	
	
	
	/**
	 * The matching level.
	 */
	private UserPermission level;

	/**
	 * The matching authorization flag.
	 */
	private Boolean authorized;

	/**
	 * Builds a new User Matcher.
	 */
	public UserMatcher() {
		// Do nothing!
	}

	/**
	 * Sets this user matcher's name.
	 * 
	 * @param name
	 *            this user matcher's name
	 * @return this same user matcher
	 */
	public UserMatcher setName(String name) {
		this.name = name;
		return this;
	}

	/**
	 * Sets this user matcher's name checking type.
	 * 
	 * @param nameType
	 *            this user matcher's name checking type.
	 * @return this same user matcher
	 */
	public UserMatcher setNameSearchType(StringMatchingType nameType) {
		this.nameType = nameType;
		return this;
	}

	public Boolean isNameSensitive() {
		return nameSensitive;
	}

	public UserMatcher setNameSensitive(boolean nameSensitive) {
		this.nameSensitive = nameSensitive;
		return this;
	}

	public Boolean isEmailSensitive() {
		return emailSensitive;
	}

	public UserMatcher setEmailSensitive(boolean emailSensitive) {
		this.emailSensitive = emailSensitive;
		return this;
	}

	public Boolean isLoginSensitive() {
		return loginSensitive;
	}

	public UserMatcher setLoginSensitive(boolean loginSensitive) {
		this.loginSensitive = loginSensitive;
		return this;
	}

	/**
	 * Sets this user matcher's login.
	 * 
	 * @param login
	 *            this user matcher's login.
	 * @return this same user matcher
	 */
	public UserMatcher setLogin(String login) {
		this.login = login;
		return this;
	}

	/**
	 * Sets this user matcher's login checking type.
	 * 
	 * @param loginType
	 *            this user matcher's login checking type.
	 * @return this same user matcher
	 */
	public UserMatcher setLoginSearchType(StringMatchingType loginType) {
		this.loginType = loginType;
		return this;
	}

	/**
	 * Sets this user matcher's email.
	 * 
	 * @param email
	 *            this user matcher's email.
	 * @return this same user matcher
	 */
	public UserMatcher setEmail(String email) {
		this.email = email;
		return this;
	}

	/**
	 * Sets this user matcher's email checking type.
	 * 
	 * @param emailType
	 *            this user matcher's email checking type.
	 * @return this same user matcher
	 */
	public UserMatcher setEmailSearchType(StringMatchingType emailType) {
		this.emailType = emailType;
		return this;
	}

	/**
	 * Sets this user matcher's level.
	 * 
	 * @param level
	 *            this user matcher's level.
	 * @return this same user matcher
	 */
	public UserMatcher setUserLevel(UserPermission level) {
		this.level = level;
		return this;
	}

	/**
	 * Sets this user matcher's authorization flag.
	 * 
	 * @param authorized
	 *            this user matcher's authorization flag.
	 * @return this same user matcher
	 */
	public UserMatcher setAuthorized(Boolean authorized) {
		this.authorized = authorized;
		return this;
	}

	public StringMatchingType getNameType() {
		return nameType;
	}

	public void setNameType(StringMatchingType nameType) {
		this.nameType = nameType;
	}

	public StringMatchingType getEmailType() {
		return emailType;
	}

	public void setEmailType(StringMatchingType emailType) {
		this.emailType = emailType;
	}

	public StringMatchingType getLoginType() {
		return loginType;
	}

	public void setLoginType(StringMatchingType loginType) {
		this.loginType = loginType;
	}

	public UserPermission getLevel() {
		return level;
	}

	public void setLevel(UserPermission level) {
		this.level = level;
	}

	public String getName() {
		return name;
	}

	public String getEmail() {
		return email;
	}

	public String getLogin() {
		return login;
	}

	public Boolean getAuthorized() {
		return authorized;
	}

	@Override
	public String toString() {
		StringBuilder bld = new StringBuilder();
		bld.append("Login: ");
		bld.append(this.name);
		bld.append("\n");
		bld.append("Login sensitive: ");
		bld.append(this.loginSensitive);
		bld.append("\n");
		bld.append("Login Matching Type: ");
		bld.append(this.loginType);
		bld.append("\n");
		bld.append("Name: ");
		bld.append(this.name);
		bld.append("\n");
		bld.append("Name sensitive: ");
		bld.append(this.nameSensitive);
		bld.append("\n");
		bld.append("Name Matching Type: ");
		bld.append(this.nameType);
		bld.append("\n");
		bld.append("Email: ");
		bld.append(this.email);
		bld.append("\n");
		bld.append("Email sensitive: ");
		bld.append(this.emailSensitive);
		bld.append("\n");
		bld.append("Email Matching Type: ");
		bld.append(this.emailType);
		bld.append("\n");
		bld.append("Level: ");
		bld.append(this.level);
		bld.append("\n");
		bld.append("Authorized: ");
		bld.append(this.authorized);
		bld.append("\n");
		return bld.toString();
	}
}
